<?php ini_set('display_errors',1); 
 error_reporting(E_ALL & ~E_NOTICE);
//============================================================+
// File name   : example_006.php
// Begin       : 2008-03-04
// Last Update : 2010-08-08
//
// Description : Example 006 for TCPDF class
//               WriteHTML and RTL support
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com s.r.l.
//               Via Della Pace, 11
//               09044 Quartucciu (CA)
//               ITALY
//               www.tecnick.com
//               info@tecnick.com
//============================================================+

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: WriteHTML and RTL support
 * @author Nicola Asuni
 * @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
 * @link http://tcpdf.org
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
 * @since 2008-03-04
 */ 
//defined('_JEXEC') or die('Restricted access');
//header("Content-type: application/pdf");
//global $mainframe;
//$document =& JFactory::getDocument();

// Get Joomla! framework

define( '_JEXEC', 1 );
define( '_VALID_MOS', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../../../..'));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
JLoader::import('joomla.application.component.model'); 
//JLoader::import('WRecruit',JPATH_BASE.DS.'components' . DS . 'com_wrecruit' . DS . 'models' );  
include_once('../../../models/wrecruit.php');
$candidate = new WRecruitModelWRecruit();
//$candidate = JModel::getInstance('WRecruit','WRecruitModel');
//Check if model WRecruitModelWRecruit exist
	//Check Authiontication
	$user	=& JFactory::getUser();
	if(isset($user->id) && $user->id == 0 || $user->id == ''){
		   $app =& JFactory::getApplication(); 
		   echo JText::_( 'Please Login' );
		   return;
	}else{
		$candidateObj = $candidate->getAllCandidatesInfor($user->id);
		if( !$candidateObj ){
			$app =& JFactory::getApplication(); 
		   //add a message to the message queue
			echo  JText::_( 'Please Login' );
			return;
		}
		
	}

//echo 'http://'.$_SERVER["SERVER_NAME"].'/wrecruitdata/photo/'.$candidateObj->photo; exit();

if($candidate){
    //Registric resume access
	if(!$candidate->checkAuticationResume($user->id,JRequest::getVar('id'))){
		  $session = &JFactory::getSession();
		  $msg = $session->get('job_msg');
		  echo $msg;
		  return;
	}
  if ($data = $candidate->getCvViewInfoById(JRequest::getVar('id')) ) {
  
	require_once(JPATH_BASE.DS.'tcpdf'.DS.'config'.DS.'lang'.DS.'eng.php');
	require_once(JPATH_BASE.DS.'tcpdf'.DS.'tcpdf.php');
	require_once(JPATH_BASE.DS.'tcpdf'.DS.'htmlcolors.php');
	
	// create new PDF document
	$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

	// set document information
	$pdf->SetCreator(PDF_CREATOR);
	$pdf->SetAuthor('&nbsp;');
	$pdf->SetTitle('Print Quotation');
	$pdf->SetSubject('&nbsp;');
	$pdf->SetKeywords('&nbsp;');

	// set default header data
	//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
	$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

	// set header and footer fonts
	$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
	$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

	// set default monospaced font
	$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

	//set margins
	$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
	$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
	$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

	//set auto page breaks
	$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

	//set image scale factor
	$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

	//set some language-dependent strings
	$pdf->setLanguageArray($l);

	// ---------------------------------------------------------

	// set font
	$pdf->SetFont('dejavusans', '', 10);

	// add a page
	$pdf->AddPage();
	// writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
	// writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true)
	
	$html = '';
	$b_date = $data->date_of_birth;
	$b_date = explode('-',$b_date);
	if(count($b_date) >0){
		$data->date_of_birth = $b_date[2].'/'.$b_date[1].'/'.$b_date[0];
	}
	$g = ($data->gender_id=1)?'Male':'Female';
	$html ='
			<table border="0">
		  <tr>
			<td colspan="3">&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan="3"><table border="0">
			  <tr>
				<td >Name:</td>
				<td >'.$candidateObj->firstname.' '.$candidateObj->lastname.'</td>
				<td >&nbsp;</td>
				<td  rowspan="6"><img height="100" width="100" src="http://'.$_SERVER["SERVER_NAME"].'/wrecruitdata/photo/'.$candidateObj->photo.'"></td>
			  </tr>
			  <tr>
				<td>Nationality:</td>
				<td>Cambodian*</td>
				<td>&nbsp;</td>
				</tr>
			  <tr>
				<td>Date of Birth:</td>
				<td>'.$data->date_of_birth.'</td>
				<td>&nbsp;</td>
				</tr>
			  <tr>
				<td>Marital Status:</td>
				<td>Single*</td>
				<td>&nbsp;</td>
				</tr>
			  <tr>
				<td>Gender:</td>
				<td>'.$g.'</td>
				<td>&nbsp;</td>
				</tr>
			  <tr>
				<td>Place of Birth:</td>
				<td>***</td>
				<td>&nbsp;</td>
				</tr>
			  <tr>
				<td>Present Address:</td>
				<td>'.$candidateObj->address.'</td>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			  </tr>
			  <tr>
				<td>Contact Number:</td>
				<td>'.$candidateObj->phone.'</td>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			  </tr>
			  <tr>
				<td>E-mail:</td>
				<td>'.$candidateObj->EMAIL.'</td>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			  </tr>
			</table></td>
		  </tr>
		  <tr>
			<td colspan="3">Remuneration* / Salary: '.$data->SALARY.' My present package is* </td>
		  </tr>
		  <tr>
			<td colspan="3">Notice Period / Other: <input type="checkbox" /> one week <input type="checkbox" /> two weeks <input type="checkbox" /> one month <input type="checkbox" /> other (please specify)...</td>
		  </tr>
		  <tr>
			<td colspan="3">&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan="3"><strong>ACADEMIC BACKGROUND</strong></td>
		  </tr>
		  <tr>
			<td colspan="3"><table  border="0">
			';
			$htmls = '';
		if ( $datapro = $candidate->getEducationList(JRequest::getVar('id')) ) {
		 $n = 3;
		  for ( $i = 0; $i <= $n; $i++) {
					if ($i==0) {
						$sub_fix ='';
					} else {
						$sub_fix =$i;
					}
				 if($datapro["institute".$sub_fix] != ""){
					
					$htmls .='
					  <tr>
						<td >Year '.$datapro['institute'.$sub_fix.'_cert_year'].':</td>
						<td >'.$datapro['institute'.$sub_fix].'</td>
					  </tr>';
		        }
		 }
		}
		$html .= $htmls;
		$html .=' 
		 </table>
		 </td>
		  </tr>
		  <tr>
			<td colspan="3">&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan="3"><strong>TRAINING PROGRAMS COMPLETED</strong></td>
		  </tr>
		  <tr>
			<td colspan="3"><table  border="0">
			';
			  $htmls = '';
			  if ( $datapro = $candidate->getEducationList(JRequest::getVar('id')) ) {
				 $n = 3;
				  for ( $i = 0; $i <= $n; $i++) {
							if ($i==0) {
								$sub_fix ='';
							} else {
								$sub_fix =$i;
							}
						 if($datapro["institute".$sub_fix] != ""){
							
							$htmls .='
							  <tr>
								<td >Day/Month/Year(Present) Year '.$datapro['institute'.$sub_fix.'_cert_year'].':</td>
								<td >'.$datapro['institute'.$sub_fix].'</td>
							  </tr>';
						}
				 }
				}
		$html .= $htmls;
		$html .='</table></td>
		  </tr>
		  <tr>
			<td colspan="3">&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan="3"><table  border="0">
			  <tr>
				<td ><strong>LANGUAGES</strong></td>
				<td >Khmer  Native language<br>
				  English  Good/Very good<br>
				  (Others languages)</td>
			  </tr>
			  <tr>
				<td><strong>COMPUTER SKILLS</strong></td>
				<td>';
				$htmls = '';
				if ( $data = $candidate->getSkillsListByResumeId(JRequest::getVar('id')) ) {
					 $n = count($data);
						 for ( $i = 0; $i < $n; $i++) {
								
								$htmls .='
									'.$data[$i]->skill_name.' &nbsp;'; 
								
								
						  }
				}
			$html .= $htmls;
			$html .= '</td>
			  </tr>
			  <tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			  </tr>
			</table></td>
		  </tr>
		  <tr>
			<td colspan="3">&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan="3"><strong>Professional experiences</strong></td>
		  </tr>
		  <tr>
			<td colspan="3">';
		   $htmls = '';
		   if ( $data = $candidate->getProListByResumeId(JRequest::getVar('id')) ) {
			 $n = count($data);
				 
				 for ( $i = 0; $i < $n; $i++) {
				   $htmls .='
					<table border="0">
					  <tr>
						<td >Company name: <strong>'.$data[$i]->employer.'</strong></td>
						<td >from '.date('M-Y',strtotime($data[$i]->employer_from_date)).' - '.date('M-Y',strtotime($data[$i]->employer_to_date)).'</td>
						<td >&nbsp;</td>
					  </tr>
					  <tr>
						<td>Title: </td>
						<td>'.$data[$i]->employer_position.'</td>
						<td>&nbsp;</td>
					  </tr>
					  <tr>
						<td>Responsibilities:</td>
						<td>&nbsp;</td>
						<td>&nbsp;</td>
					  </tr>
					  <tr>
						<td colspan="3">
							'.$data[$i]->employer_resp.'
						</td>
						</tr>
					</table>';
			
			  }
		   }
			
		
		 $html .= $htmls;	
		 $html .='	</td>
		  </tr>
		  <tr>
			<td colspan="3">&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan="3"><strong>REFERENCES</strong></td>
		  </tr>';
		  $htmls = '';
		  if ( $data = $candidate->getReferenceList(JRequest::getVar('id')) ) {
				 $n = 3;
				 for ( $i = 0; $i <= $n; $i++) {
						$subfix = $i;
						if ( $i == 0 ) {
							$subfix = '';
						} 
					  if ( $data['reference'.$subfix.'_name'] != '') { 
					  $htmls .='<tr>
						<td colspan="3">Name: '.$data['reference'.$subfix].' Title*:.......Company name*: .........Tel: '.$data['reference'.$subfix.'_phone'].'</td>
					  </tr>';
		  		   }
				 }
				
			}
		  $html .= $htmls;
		  $html .= '<tr>
			<td colspan="3">&nbsp;</td>
		  </tr>
		  <tr>
			<td colspan="3">I hereby declare that all the information provided in this resume is correct and accurate.</td>
		  </tr>
		  <tr>
			<td colspan="3">&nbsp;</td>
		  </tr>
		  <tr>
			<td>Applicant signature............</td>
			<td>&nbsp;</td>
			<td>Date:...............</td>
		  </tr>
		</table>
	';
	// output the HTML content
	$pdf->writeHTML($html, true, false, true, false, '');
	// reset pointer to the last page
	$pdf->lastPage();
	// ---------------------------------------------------------
	//Close and output PDF document
	ob_end_clean();
	$pdf->Output('resume1.pdf', 'I');

	//============================================================+
	// END OF FILE                                                
	//============================================================+
 }//End if Cv Data
}
